package com.tt.aile.upload.controller;

import com.tt.aile.upload.service.UploadService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author 86176 shkstrat
 * @date 2020/9/24 - 16:11
 */
@Controller
@RequestMapping("upload")
public class UploadController {

    @Autowired
    UploadService uploadService;

//    @RequestMapping("image")
//    @ResponseBody
    @PostMapping("image")
//    public String uploadImage(){
        public ResponseEntity<String> uploadImage(@RequestParam("file") MultipartFile file){


        System.out.println("----------------------jj------");
        String url =this.uploadService.uploadImage(file);
        if (StringUtils.isBlank(url)){
            return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
        }
        return ResponseEntity.status(HttpStatus.CREATED).body(url);
//        return "ss";
    }
}
